/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1639226667031_9335';

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  //配置数据库
  config.mysql = {
    // database configuration
    client: {
      host: 'localhost',
      port: '3306',
      user: 'blog',
      password: '123456',
      database: 'blog',    
    },
    // load into app, default is open
    app: true,
    // load into agent, default is close
    agent: false,
  };


  //配置egg-cors卡与请求
  //安全机制
  //scrf: false 关闭安全机制
  // 需要配合 security 插件一块使用
  config.security={
    csrf:{ // 关闭 csrf
      enable:false
    },
    // 跨域白名单 'http://localhost:3000
    domainWhiteList:['*']
  }
  // 允许跨域的方法
  config.cors={
    origin:'http://localhost:3000', //匹配规则 域名+端口 * 表示全匹配
    credentials:true, //运行cookie的跨域 seesion是cookie的一种
    allowMethods:'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS' //哪些请求方式可以跨域访问
  };


  return {
    ...config,
    ...userConfig,
  };
};
